﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

// Condition: Write a program that finds the sequence of maximal sum in given array


class MaxSeqSum
{
    static void Main()
    {
        // 1. Declare array of N elements and helping variables
        Console.Write("Enter number of elements N: ");
        int N = int.Parse(Console.ReadLine());
        int[] myArr = new int[N];
        Console.WriteLine("Enter elements of integer array: ");
        for (int index = 0; index < N; index++)
        {
            Console.Write("element[{0}]= ", index);
            myArr[index] = int.Parse(Console.ReadLine());
        }
        Console.WriteLine();
        int start=-1;
        int end=-1;
        int bestStart=-1;
        int bestEnd=-1;
        int sum = 0;
        int maxSum = int.MinValue;

        // 2. Use two loops to find start and end index of sequence with max sum

        for (int i = 0; i < myArr.Length-1; i++)
        {
            sum = 0;
            for (int j = i; j < myArr.Length; j++)
            {
                sum = sum + myArr[j];
                start = i;
                end = j;
                if (sum > maxSum)
                {
                    maxSum = sum;
                    bestStart = start;
                    bestEnd = end;
                }
            }
            
        }

        // 3. Print sequence with max Sum
        Console.Write("The sequence with maximal value is:{ ");
        for (int i = bestStart; i <= bestEnd; i++)
        {
            Console.Write(myArr[i]+" ");
        }
        Console.WriteLine("}");


    }
}

